package com.cin.cma.server.pos.service.impl;


import com.cin.cma.common.model.finixx.base.BaseResponse;
import com.cin.cma.common.model.finixx.request.*;
import com.cin.cma.common.model.finixx.response.VoucherPayPolicyResponse;
import com.cin.cma.common.model.finixx.response.VoucherRedeemResponse;
import com.cin.cma.common.model.finixx.response.VoucherResponse;
import com.cin.cma.common.model.finixx.response.VoucherTempLockResponse;
import com.cin.cma.common.constant.FunctionCode;
import com.cin.cma.server.pos.service.IProxyRequestService;
import com.cin.cma.server.pos.service.IVoucherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @Date：2024-07-18 14:46
 */
@Slf4j
@Service
public class VoucherServiceImpl implements IVoucherService {
    @Autowired
    private IProxyRequestService proxyRequestService;

    /**
     * 退款兑换券(兑换券退票时需手动退券)
     *
     * @param model
     * @return
     */
    @Override
    public BaseResponse refund(VoucherRefundRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_REFUND);
        return this.proxyRequestService.context(model, BaseResponse.class);
    }

    /**
     * 获取礼券
     *
     * @param model
     * @return
     */
    @Override
    public VoucherResponse get(VoucherGetRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_GET);
        return this.proxyRequestService.context(model, VoucherResponse.class);
    }

    /**
     * 临时锁定券
     *
     * @param model
     * @return
     */
    @Override
    public VoucherTempLockResponse tempLock(VouVoucherTempLockRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_TEMP_LOCK);
        return this.proxyRequestService.context(model, VoucherTempLockResponse.class);
    }

    /**
     * 券兑换接口
     *
     * @param model
     * @return
     */
    @Override
    public VoucherRedeemResponse redeem(VoucherRedeemRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_REDEEM);
        return this.proxyRequestService.context(model, VoucherRedeemResponse.class);
    }

    /**
     * 券兑换回滚
     *
     * @param model
     * @return
     */
    @Override
    public BaseResponse redeemRollback(VoucherRedeemRollbackRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_REDEEM_ROLLBACK);
        return this.proxyRequestService.context(model, BaseResponse.class);
    }

    /**
     * 券政策获取
     *
     * @param model
     * @return
     */
    @Override
    public VoucherPayPolicyResponse getPayPolicy(VoucherPayPolicyRequest model) throws Exception {
        model.setCode(FunctionCode.VOUCHER_GET_PAYPOLICY);
        return this.proxyRequestService.context(model, VoucherPayPolicyResponse.class);
    }
}
